package edu.gatech.volt2.drdoommgt.gui;

import java.awt.EventQueue;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.SpringLayout;
import javax.swing.border.EmptyBorder;

public class PrescriptionView extends JFrame implements IPrescriptionView {
	private JPanel contentPane;
	private JTextField dosage;
	private JTextField instructions;
	private JTextField price;
	private JTextField drug;
	private JButton addButton;
	private JButton cancelButton;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					PatientInvoice frame = new PatientInvoice();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public PrescriptionView() {
		setTitle("Dr. Doom Management Prescription");
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 350, 207);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		SpringLayout sl_contentPane = new SpringLayout();
		contentPane.setLayout(sl_contentPane);
		
		JLabel lblPatient = new JLabel("Drug:");
		sl_contentPane.putConstraint(SpringLayout.NORTH, lblPatient, 16, SpringLayout.NORTH, contentPane);
		sl_contentPane.putConstraint(SpringLayout.WEST, lblPatient, 30, SpringLayout.WEST, contentPane);
		contentPane.add(lblPatient);
		
		JLabel lblDateOfVisit = new JLabel("Dosage:");
		sl_contentPane.putConstraint(SpringLayout.NORTH, lblDateOfVisit, 19, SpringLayout.SOUTH, lblPatient);
		sl_contentPane.putConstraint(SpringLayout.WEST, lblDateOfVisit, 0, SpringLayout.WEST, lblPatient);
		contentPane.add(lblDateOfVisit);
		
		JLabel lblDoctor = new JLabel("Instructions:");
		sl_contentPane.putConstraint(SpringLayout.NORTH, lblDoctor, 13, SpringLayout.SOUTH, lblDateOfVisit);
		sl_contentPane.putConstraint(SpringLayout.WEST, lblDoctor, 0, SpringLayout.WEST, lblPatient);
		contentPane.add(lblDoctor);
		
		JLabel lblServices = new JLabel("Price:");
		sl_contentPane.putConstraint(SpringLayout.NORTH, lblServices, 18, SpringLayout.SOUTH, lblDoctor);
		sl_contentPane.putConstraint(SpringLayout.WEST, lblServices, 0, SpringLayout.WEST, lblPatient);
		contentPane.add(lblServices);
		
		dosage = new JTextField();
		sl_contentPane.putConstraint(SpringLayout.NORTH, dosage, -6, SpringLayout.NORTH, lblDateOfVisit);
		sl_contentPane.putConstraint(SpringLayout.WEST, dosage, 46, SpringLayout.EAST, lblDateOfVisit);
		sl_contentPane.putConstraint(SpringLayout.EAST, dosage, 122, SpringLayout.EAST, lblDateOfVisit);
		contentPane.add(dosage);
		dosage.setColumns(10);
		
		instructions = new JTextField();
		sl_contentPane.putConstraint(SpringLayout.NORTH, instructions, -6, SpringLayout.NORTH, lblDoctor);
		sl_contentPane.putConstraint(SpringLayout.WEST, instructions, 17, SpringLayout.EAST, lblDoctor);
		sl_contentPane.putConstraint(SpringLayout.EAST, instructions, -15, SpringLayout.EAST, contentPane);
		contentPane.add(instructions);
		instructions.setColumns(10);
		
		addButton = new JButton("Add");
		sl_contentPane.putConstraint(SpringLayout.EAST, addButton, 0, SpringLayout.EAST, contentPane);
		contentPane.add(addButton);
		
		cancelButton = new JButton("Cancel");
		sl_contentPane.putConstraint(SpringLayout.NORTH, addButton, 0, SpringLayout.NORTH, cancelButton);
		sl_contentPane.putConstraint(SpringLayout.WEST, cancelButton, 10, SpringLayout.WEST, contentPane);
		sl_contentPane.putConstraint(SpringLayout.SOUTH, cancelButton, 0, SpringLayout.SOUTH, contentPane);
		contentPane.add(cancelButton);
		
		JLabel lblMg = new JLabel("mg");
		sl_contentPane.putConstraint(SpringLayout.WEST, lblMg, 6, SpringLayout.EAST, dosage);
		sl_contentPane.putConstraint(SpringLayout.SOUTH, lblMg, 0, SpringLayout.SOUTH, lblDateOfVisit);
		contentPane.add(lblMg);
		
		JLabel label = new JLabel("$");
		sl_contentPane.putConstraint(SpringLayout.NORTH, label, 0, SpringLayout.NORTH, lblServices);
		sl_contentPane.putConstraint(SpringLayout.WEST, label, 68, SpringLayout.EAST, lblServices);
		contentPane.add(label);
		
		price = new JTextField();
		sl_contentPane.putConstraint(SpringLayout.WEST, price, 6, SpringLayout.EAST, label);
		sl_contentPane.putConstraint(SpringLayout.EAST, price, 0, SpringLayout.EAST, lblMg);
		sl_contentPane.putConstraint(SpringLayout.NORTH, price, -6, SpringLayout.NORTH, lblServices);
		contentPane.add(price);
		price.setColumns(10);
		
		drug = new JTextField();
		sl_contentPane.putConstraint(SpringLayout.WEST, drug, 0, SpringLayout.WEST, dosage);
		sl_contentPane.putConstraint(SpringLayout.SOUTH, drug, -6, SpringLayout.NORTH, dosage);
		sl_contentPane.putConstraint(SpringLayout.EAST, drug, 0, SpringLayout.EAST, instructions);
		contentPane.add(drug);
		drug.setColumns(10);
	}

	@Override
	public JButton getCancelButton() {
		return cancelButton;
	}

	@Override
	public JButton getAddButton() {
		return addButton;
	}

	@Override
	public Double getDosage() {
		return new Double(dosage.getText());
	}

	@Override
	public String getDrug() {
		return drug.getText();
	}

	@Override
	public Double getPrice() {
		return new Double(price.getText());
	}

	@Override
	public String getInstructions() {
		return instructions.getText();
	}

	@Override
	public void showSelf() {
		this.setVisible(true);	
	}
	

	@Override
	public void addListener(ActionListener al) {
		addButton.addActionListener(al);
		cancelButton.addActionListener(al);
	}

	@Override
	public void hideSelf() {
		this.setVisible(false);
	}
}
